package mis510.homefinders;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class GetPW extends Activity{
	Button sbmBtn;
	EditText email;
	Intent nextActivity;
	TextView registerScreen;
	Button bk_btn;
	DBUserAdapter dbUser = new DBUserAdapter(GetPW.this);
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.getpw);
        
        sbmBtn = (Button)findViewById(R.id.sbmBtn);
        registerScreen = (TextView) findViewById(R.id.link_to_register);
        email = (EditText)findViewById(R.id.email);
        bk_btn = (Button) findViewById(R.id.bk_btn);
    	dbUser.open();
        
        sbmBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	String email_pw = email.getText().toString();
            	if (String.valueOf(email_pw).trim().length() >0)
            	{
            		//nextActivity = new Intent(SearchProperty.this, Evaluation.class);
            		//startActivity(nextActivity);
            		//nextActivity.putExtra("address", address);
            		//startActivityForResult(nextActivity, 1);
            		//DBUserAdapter dbUser = new DBUserAdapter(GetPW.this);
    				dbUser.open();
    				if(dbUser.Pwretrieve(email_pw))
    				{
    					Toast.makeText(GetPW.this,"User name and Password have been sent to "+email_pw, Toast.LENGTH_LONG).show();
    					dbUser.close();
    					nextActivity = new Intent(GetPW.this, Rm_login_req.class);
    		        	startActivity(nextActivity);
    				}
    				else
    					Toast.makeText(GetPW.this,"No information matches Email", Toast.LENGTH_LONG).show();
    				dbUser.close();
            	}
            	else
            		Toast.makeText(GetPW.this,"Please fill out Email address", Toast.LENGTH_LONG).show();
            }
        });
        
        
        registerScreen.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // Switching to Register screen
                String url = "http://ec2-54-245-183-169.us-west-2.compute.amazonaws.com:8080/HomeFinders/index.html";  //change to our website
                Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
                startActivity(i);
            }
        });
        
        bk_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            	nextActivity = new Intent(GetPW.this, Rm_login_req.class);
            	startActivity(nextActivity);
            }
        });
	}

}
